layui.use(['table'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var util = layui.util;
    
    //获取到当前登录的用户
	var user = JSON.parse(sessionStorage.getItem("user"));
    
    var initJobListNo = function(){
    	//页面一加载查询工作单信息并赋值给下拉框
        $.get("delivery/pack/findAllPackSuccess", function(result){
        	for (let i in result) {
        		$("#jobListNo").append(new Option(result[i], result[i]));
        	}
        	form.render('select'); // 更新下拉框
        });
    }
    //加载工作单号
    initJobListNo();
    
    //全局对象
    var pack = null;
    
    //下拉框选中事件
    form.on('select(jobListNo)', function(data){
    	//发送请求查询工作单的详细信息
    	$.get("delivery/pack/findBarCodeInfo?jobListNo="+data.value, function(res){
    		$("#dytm input[name=stripeCode]").val(res.stripeCode);
    		$("#dytm input[name=storageTime]").val(util.toDateString(res.storageTime, "yyyy-MM-dd HH:mm:ss"));
    		$("#dytm input[name=factQuantity]").val(res.factQuantity);
    		$("#dytm input[name=product]").val(res.product);
    		$("#dytm input[name=sender]").val(res.sender);
    		$("#dytm input[name=senderAddress]").val(res.senderAddress);
    		$("#dytm input[name=senderCellPhone]").val(res.senderCellPhone);
    		$("#dytm input[name=addressee]").val(res.addressee);
    		$("#dytm input[name=addresseeAddress]").val(res.addresseeAddress);
    		$("#dytm input[name=addresseeCellPhone]").val(res.addresseeCellPhone);
    		$("#dytm input[name=returnProductSign]").val(res.returnProductSign);
    		
    		//赋值给全局
    		pack = res;
    	});
    	
    });
    
    //打印条码表单提交
    $("#sctm").click(function(){
    	//判断是否选中
    	if ($("#jobListNo").val() == "") {
    		layer.alert("请选择一个工作单！");
    	}
    	//显示数据表格
    	$("#barCodeTable").show();
    	//赋值
    	$("#jobListNo_1").text(pack.jobListNo);
    	$("#storageTime").text(util.toDateString(pack.storageTime, "yyyy-MM-dd HH:mm:ss"));
    	$("#factQuantity").text(pack.factQuantity);
    	$("#product").text(pack.product);
    	$("#sender").text(pack.sender);
    	$("#senderAddress").text(pack.senderAddress);
    	$("#senderCellPhone").text(pack.senderCellPhone);
    	$("#addressee").text(pack.addressee);
    	$("#addresseeAddress").text(pack.addresseeAddress);
    	$("#addresseeCellPhone").text(pack.addresseeCellPhone);
    	$("#barCode").JsBarcode(pack.stripeCode);
    });
    
});
